var _n7;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2UIManager = require("UIManager");
var $2DataManager = require("DataManager");
var $2ZombieMgr = require("ZombieMgr");
var $2ExcelManager = require("ExcelManager");
var $2Zombie = require("Zombie");
var $2Common = require("Common");
var $2BundleManager = require("BundleManager");
var $2PoolManager = require("PoolManager");
var $2TombStone = require("TombStone");
var $2TaSdk = require("TaSdk");
var $2UserDataManager = require("UserDataManager");
var $2Hts = require("Hts");
var $2Kapai = require("Kapai");
var $2putongjianguo = require("putongjianguo");
var $2AudioManager = require("AudioManager");
var $2FlbMathUtil = require("FlbMathUtil");
var $2ADManager = require("ADManager");
var $2pvzChannel = require("pvzChannel");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_BowlingUI = _n7 = /* */function (_cc$Component7) {
  babel_inherits(n, _cc$Component7);
  var _super8 = babel_createSuper(n);
  function n() {
    var _this20;
    babel_classCallCheck(this, n);
    _this20 = _super8.apply(this, arguments);
    _this20.groudNode = null;
    _this20.goldNumLabel = null;
    _this20.gameProgress = null;
    _this20.gdts = null;
    _this20.speed = 300;
    _this20.zombieInRow = new Array();
    _this20.zombieSet = new Set();
    _this20.allTime = 0;
    _this20.nowTime = 0;
    _this20.isPlay = false;
    _this20.isGuide = false;
    _this20.ptjianguo = null;
    _this20.Kapais = null;
    _this20.hongxian = null;
    _this20.groudXMin = $2DataManager.default.instance.groudStartPo.x;
    _this20.groudXMax = $2DataManager.default.instance.groudStartPo.x + $2DataManager.default.instance.blockWidth * $2DataManager.default.instance.col;
    _this20.groudYMin = $2DataManager.default.instance.groudStartPo.y;
    _this20.groudYMax = $2DataManager.default.instance.groudStartPo.y + $2DataManager.default.instance.blockHeight * $2DataManager.default.instance.row;
    _this20.blq_zaxiang = [];
    _this20.bxq_jianguo = [];
    _this20.count = 0;
    _this20.jianguo_info = null;
    _this20.bombNums = 0;
    _this20.lbs_btn = null;
    _this20.bs1 = null;
    _this20.bs2 = null;
    _this20.bs_btn = null;
    _this20.bs_bg = null;
    _this20.is_lbs = false;
    _this20.showBug = null;
    _this20.startClickTime = 0;
    _this20.clickTime = 0;
    _this20.is_bug = false;
    return _this20;
  }
  babel_createClass(n, [{
    key: "onLoad",
    value: function onLoad() {
      $2UIManager.default.instance.hideUI("MoneyPanelUI");
      this.lbs_btn = cc.find("lbs_btn", this.node);
      this.bs1 = cc.find("lbs_btn/bs_bg/bs1", this.node);
      this.bs2 = cc.find("lbs_btn/bs_bg/bs2", this.node);
      this.bs_btn = cc.find("lbs_btn/bs_bg/bs_btn", this.node);
      this.bs_bg = cc.find("lbs_btn/bs_bg", this.node);
      this.showBug = cc.find("showBug", this.node);
      this.bs_bg.on(cc.Node.EventType.TOUCH_START, this.on_lbs, this);
      this.showBug.on(cc.Node.EventType.TOUCH_START, this.on_showBug, this);
      this.showBug.on(cc.Node.EventType.TOUCH_END, this.on_showBug_end, this);
      this.bs_btn.setPosition(this.bs2.position);
      this.gdts = cc.find("chuangkou/gdts", this.node);
      this.Kapais = cc.find("chuangkou/Kapais", this.node);
      this.hongxian = cc.find("groud/Gird/hongxian", this.node);
      this.gdts.children[1].x = this.gdts.children[0].width;
      $2DataManager.default.instance.is_bowling = true;
      this.count = 1;
      this.init();
      this.schedule(this.kapai_move, .02, cc.macro.REPEAT_FOREVER, .02);
      this.blq_zaxiang = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.blq_zaxiang);
      this.speed = this.blq_zaxiang[1].val;
      this.bxq_jianguo = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.bxq_jianguo);
      for (var _t5 in this.bxq_jianguo) {
        if (this.count >= this.bxq_jianguo[_t5].jianguo_num[0] && this.count <= this.bxq_jianguo[_t5].jianguo_num[1]) {
          this.jianguo_info = this.bxq_jianguo[_t5];
          break;
        }
      }
      var e = $2FlbMathUtil.MathUtil.getRandomInt(0, 1);
      this.schedule(this.createKapai, this.jianguo_info.name[e], cc.macro.REPEAT_FOREVER, 1);
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      $2DataManager.default.instance.is_bowling = false;
      cc.kSpeed(1);
      this.is_lbs = false;
    }
  }, {
    key: "onEnable",
    value: function onEnable() {
      $2DataManager.default.instance.is_bowling = true;
    }
  }, {
    key: "on_showBug_end",
    value: function on_showBug_end() {
      var _this21 = this;
      if (new Date().getTime() - this.startClickTime < 400) {
        this.clickTime++;
        console.log(this.clickTime, 4444444444);
        setTimeout(function () {
          if (3 == _this21.clickTime) {
            console.log("三击事件");
            _this21.is_bug = true;
            _this21.showBug.active = false;
          }
          _this21.clickTime = 0;
        }, 400);
      }
    }
  }, {
    key: "on_showBug",
    value: function on_showBug() {
      this.startClickTime = new Date().getTime();
    }
  }, {
    key: "on_lbs",
    value: function on_lbs() {
      if (this.is_lbs) {
        cc.kSpeed(1);
        this.is_lbs = false;
        this.bs_btn.setPosition(this.bs2.position);
      } else {
        cc.kSpeed(2);
        this.is_lbs = true;
        this.bs_btn.setPosition(this.bs1.position);
      }
    }
  }, {
    key: "init",
    value: function init() {
      var _this22 = this;
      cc.dynamicAtlasManager.reset();
      _n7._instance = this;
      $2DataManager.default.instance.initBlockPos();
      $2DataManager.default.instance.level = 30;
      $2DataManager.default.instance.bowlingLevel = 1;
      $2ZombieMgr.default.instance().init(this);
      this.scheduleOnce(function () {
        _this22.play();
      }, 1);
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      switch ($2ADManager.default.instance.sdkType) {
        case $2ADManager.SDK_TYPE.Byte:
          $2ADManager.default.instance.recorderStart();
      }
    }
  }, {
    key: "on_setting",
    value: function on_setting() {
      $2UIManager.default.instance.showUI("Pause1UI");
    }
  }, {
    key: "hsjianguo",
    value: function hsjianguo(e) {
      if (!e) {
        return;
      }
      var t = babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values()).length;
      for (var _a5 = 0; _a5 < t; _a5++) {
        babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_a5] && babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_a5].node.position.sub(e).mag() < this.blq_zaxiang[3].val && babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_a5].hurt(2e3 * $2UserDataManager.default.instance.chapter);
      }
    }
  }, {
    key: "kapai_move",
    value: function kapai_move() {
      this.blq_zaxiang = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.blq_zaxiang);
      var e = this.blq_zaxiang[1].val;
      for (var _t6 = 0; _t6 < this.Kapais.childrenCount; _t6++) {
        if (0 != _t6) {
          if (this.Kapais.children[_t6].x - this.Kapais.children[_t6 - 1].x > this.Kapais.children[0].width + 10) {
            this.Kapais.children[_t6].getComponent($2Kapai.default).speed = e;
          } else {
            this.Kapais.children[_t6].getComponent($2Kapai.default).speed = 0;
          }
        } else if (this.Kapais.children[0].x < -this.Kapais.children[0].parent.width / 2 + this.Kapais.children[0].width / 2) {
          this.Kapais.children[_t6].getComponent($2Kapai.default).speed = 0;
        } else {
          this.Kapais.children[0].getComponent($2Kapai.default).speed = e;
        }
      }
    }
  }, {
    key: "createKapai",
    value: function createKapai() {
      if (this.Kapais.childrenCount >= 10) {
        return void this.unschedule(this.createKapai);
      }
      var e = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "BowlingUI/Kapai", cc.Prefab));
      e.parent = this.Kapais;
      e.x = e.parent.width / 2 + e.width + 30;
      var t = Math.random() < this.jianguo_info.num / 100 ? 2 : 1;
      e.getComponent($2Kapai.default).init(t);
      this.count++;
      e.on(cc.Node.EventType.TOUCH_START, this.start_kapai, this);
      e.on(cc.Node.EventType.TOUCH_MOVE, this.move_kapai, this);
      e.on(cc.Node.EventType.TOUCH_END, this.end_kapai, this);
      e.on(cc.Node.EventType.TOUCH_CANCEL, this.end_kapai, this);
    }
  }, {
    key: "showZombie",
    value: function showZombie() {
      var e = $2ZombieMgr.default.instance().waveData.zNum;
      var t = $2ZombieMgr.default.instance().waveData.zombieType;
      for (var _a6 = 0; _a6 < e; _a6++) {
        var _e6 = t[_a6 % t.length];
        var _n8 = $2Common.default.getZombieName(_e6);
        var _i5 = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "PoolNode/" + _n8, cc.Prefab));
        _i5.parent = this.node.getChildByName("ZombieNode");
        _i5.getComponent($2Zombie.default).reset(_e6);
        _i5.getComponent($2Zombie.default).daiji();
      }
    }
  }, {
    key: "play",
    value: function play() {
      $2ZombieMgr.default.instance().play();
      this.node.getChildByName("Gold").active = true;
      this.node.getChildByName("ZombieNode").active = false;
      this.initPlatform();
    }
  }, {
    key: "createTombstone",
    value: function createTombstone(e) {
      for (var _t7 = 0; _t7 < e.length; _t7++) {
        var _a7 = $2PoolManager.default.instance.getPoolNode("Tombstone");
        _a7.parent = this.groudNode;
        var _n9 = Math.floor((e[_t7] - 1) / 9);
        var _i6 = (e[_t7] - 1) % 9;
        _a7.getComponent($2TombStone.default).init(_n9, _i6);
        _a7.setPosition($2DataManager.default.instance.blockArr[_n9][_i6][0]);
        $2DataManager.default.instance.blockArr[_n9][_i6][1] = _a7;
      }
    }
  }, {
    key: "showProgress",
    value: function showProgress(e) {
      this.gameProgress.getChildByName("Head").zIndex = 33;
      var t = [];
      for (var _a8 = 0; _a8 < e.length; _a8++) {
        this.allTime += e[_a8];
        t.push(this.allTime);
      }
      for (var _a9 = 1; _a9 < t.length; _a9++) {
        var _e7 = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Object/Chess"));
        _e7.parent = this.gameProgress;
        _e7.x = -(this.gameProgress.width - 25) * t[_a9 - 1] / this.allTime;
      }
      this.gameProgress.active = true;
    }
  }, {
    key: "showFire",
    value: function showFire() {
      console.log("showFire");
    }
  }, {
    key: "stopZombie",
    value: function stopZombie() {
      var e = babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values()).length;
      for (var _t8 = 0; _t8 < e; _t8++) {
        babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_t8] && (babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_t8].speed = 0);
      }
    }
  }, {
    key: "lose",
    value: function lose() {
      if (20 == $2DataManager.default.instance.level) {
        $2TaSdk.default.instance.postEvent("level", {
          level: 20,
          is_Win: 0
        });
        $2Hts.default.instance.eventReport("第" + $2UserDataManager.default.instance.chapter + "周目第" + $2DataManager.default.instance.bossLevel + "级Boss关失败");
      } else {
        $2Hts.default.instance.eventReport("第" + $2UserDataManager.default.instance.chapter + "周目第" + $2DataManager.default.instance.level + "关失败");
        $2TaSdk.default.instance.postEvent("level", {
          level: $2DataManager.default.instance.level,
          is_Win: 0
        });
      }
      $2ZombieMgr.default.instance().stop();
      this.stopZombie();
      $2UIManager.default.instance.openUI("FailBowlingUI");
    }
  }, {
    key: "win",
    value: function win() {
      if (20 == $2DataManager.default.instance.level) {
        $2TaSdk.default.instance.postEvent("level", {
          level: 20,
          is_Win: 1
        });
        $2Hts.default.instance.eventReport("第" + $2UserDataManager.default.instance.chapter + "周目第" + $2DataManager.default.instance.bossLevel + "级Boss关成功");
        $2UserDataManager.default.instance.taskInfo[6].progress++;
      } else {
        $2Hts.default.instance.eventReport("第" + $2UserDataManager.default.instance.chapter + "周目第" + $2DataManager.default.instance.level + "关成功");
        $2TaSdk.default.instance.postEvent("level", {
          level: $2DataManager.default.instance.level,
          is_Win: 1
        });
        $2UserDataManager.default.instance.taskInfo[4].progress++;
      }
      $2ZombieMgr.default.instance().stop();
      this.stopZombie();
      this.scheduleOnce(function () {
        $2UIManager.default.instance.openUI("SuccessBowlingUI");
      }, 3);
    }
  }, {
    key: "move",
    value: function move(e) {
      for (var _t9 = 0; _t9 < this.gdts.childrenCount; _t9++) {
        this.gdts.children[_t9].x -= e * this.speed;
      }
      this.gdts.children[0].x < -this.gdts.children[0].width && (this.gdts.children[0].x = this.gdts.children[0].width);
      this.gdts.children[1].x < -this.gdts.children[1].width && (this.gdts.children[1].x = this.gdts.children[1].width);
    }
  }, {
    key: "start_kapai",
    value: function start_kapai(e) {
      $2AudioManager.default.instance.playEffect("blq_nqkp");
      var t = e.currentTarget.getComponent($2Kapai.default).type;
      var a = e.getLocation();
      var _n10 = this.node.convertToNodeSpaceAR(a);
      this.ptjianguo = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "BowlingUI/putongjianguo", cc.Prefab));
      this.ptjianguo.parent = this.groudNode;
      this.ptjianguo.setPosition(_n10);
      this.ptjianguo.getComponent($2putongjianguo.default).setSkin(t - 1);
      this.is_bug || (this.ptjianguo.getComponent(cc.CircleCollider).enabled = false);
    }
  }, {
    key: "move_kapai",
    value: function move_kapai(e) {
      var t = e.getLocation();
      var a = this.node.convertToNodeSpaceAR(t);
      this.ptjianguo.setPosition(a);
    }
  }, {
    key: "end_kapai",
    value: function end_kapai(e) {
      this.ptjianguo.getComponent(cc.CircleCollider).enabled = true;
      this.is_bug && (this.is_bug = false);
      $2AudioManager.default.instance.playEffect("blq_fx");
      var t = e.getLocation();
      var a = this.node.convertToNodeSpaceAR(t);
      if (a.mag() < 100) {
        return void this.ptjianguo.destroy();
      }
      var _n11 = this.groudNode.convertToNodeSpaceAR(this.hongxian.position);
      if (this.groudNode.convertToNodeSpaceAR(this.ptjianguo.position).x > _n11.x) {
        this.ptjianguo.destroy();
        return void console.log("超过红线");
      }
      var i = this.checkMovedPlantPos(a);
      if (!i) {
        this.ptjianguo.destroy();
        return void console.log("放置位置不对");
      }
      e.currentTarget.destroy();
      this.ptjianguo.setPosition(i[0].x, i[0].y - 10);
      $2DataManager.default.instance.blockArr[i[1]][i[2]][1] = this.ptjianguo;
      this.ptjianguo.getComponent($2putongjianguo.default).is_move = true;
      this.ptjianguo.getComponent($2putongjianguo.default).setVy(0);
      var s = this.ptjianguo.getComponent(sp.Skeleton);
      var l = s.setAnimation(0, "gundong", true);
      s.setTrackEventListener(l, function (e, t) {
        t.data.name;
      });
      this.ptjianguo = null;
      if (this.Kapais.childrenCount < 10) {
        for (var _t10 in this.bxq_jianguo) {
          if (this.count >= this.bxq_jianguo[_t10].jianguo_num[0] && this.count <= this.bxq_jianguo[_t10].jianguo_num[1]) {
            this.jianguo_info = this.bxq_jianguo[_t10];
            break;
          }
        }
        var _e8 = $2FlbMathUtil.MathUtil.getRandomInt(0, 1);
        this.schedule(this.createKapai, this.jianguo_info.name[_e8], cc.macro.REPEAT_FOREVER, 1);
      }
    }
  }, {
    key: "checkMovedPlantPos",
    value: function checkMovedPlantPos(e) {
      if (e.x > this.groudXMax || e.x < this.groudXMin || e.y > this.groudYMax || e.y < this.groudYMin) {
        return null;
      }
      var t = e.sub($2DataManager.default.instance.groudStartPo);
      var a = Math.floor(t.x / $2DataManager.default.instance.blockWidth);
      var _n12 = Math.floor(t.y / $2DataManager.default.instance.blockHeight);
      $2DataManager.default.instance.blockArr[_n12][a][1];
      return [$2DataManager.default.instance.blockArr[_n12][a][0], _n12, a];
    }
  }, {
    key: "onClickBomb",
    value: function onClickBomb() {
      var _this23 = this;
      if (this.bombNums > 0) {
        this.bombNums--;
        0 == this.bombNums && (this.node.getChildByName("Bomb").getChildByName("video").active = true);
        this.shootBomb();
      } else {
        var _e9 = function _e9() {
          _this23.shootBomb();
        };
        var _t11 = function _t11() {};
        var _a10 = function _a10() {};
        $2pvzChannel.pvzChannel.instance().showVideo({
          sucCall: _e9,
          failCall: _t11,
          endCall: _a10
        });
      }
    }
  }, {
    key: "shootBomb",
    value: function shootBomb() {
      var _this24 = this;
      this.node.getChildByName("Bomb").getComponent(cc.Button).interactable = false;
      var e = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Object/Bomb"));
      e.parent = this.node.getChildByName("Bomb");
      var t = e.getComponent(sp.Skeleton).setAnimation(0, "baozha", false);
      e.getComponent(sp.Skeleton).setTrackEventListener(t, function (e, t) {
        console.log("event===", t);
        if ("baozha" == t.data.name) {
          $2AudioManager.default.instance.playEffect("HuangGuaEff");
          var _e10 = babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values()).length;
          for (var _t12 = 0; _t12 < _e10; _t12++) {
            babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_t12] && babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_t12].hurt(2e3 * $2UserDataManager.default.instance.chapter);
          }
        }
      });
      e.getComponent(sp.Skeleton).setCompleteListener(function () {
        _this24.node.getChildByName("Bomb").getComponent(cc.Button).interactable = true;
        e.destroy();
        2 == $2DataManager.default.instance.level && $2UIManager.default.instance.uiList.GuideUI2 && $2UIManager.default.instance.uiList.GuideUI2.emit("nextStep");
      });
    }
  }, {
    key: "showBomb",
    value: function showBomb() {
      this.node.getChildByName("Bomb").active = true;
      if (this.bombNums > 0) {
        this.node.getChildByName("Bomb").getChildByName("video").active = false;
      } else {
        this.node.getChildByName("Bomb").getChildByName("video").active = true;
      }
    }
  }, {
    key: "update",
    value: function update(e) {
      this.move(e);
      if (this.isPlay && !this.isGuide) {
        this.nowTime += e;
        this.gameProgress.getComponent(cc.ProgressBar).progress = this.nowTime / this.allTime;
        this.gameProgress.getChildByName("Head").x = -this.gameProgress.getComponent(cc.ProgressBar).progress * this.gameProgress.width;
      }
    }
  }], [{
    key: "instance",
    get() {
      return this._instance;
    }
  }]);
  return n;
}(cc.Component);
def_BowlingUI._instance = null;
cc__decorate([ccp_property(cc.Node)], def_BowlingUI.prototype, "groudNode", undefined);
cc__decorate([ccp_property(cc.Label)], def_BowlingUI.prototype, "goldNumLabel", undefined);
cc__decorate([ccp_property(cc.Node)], def_BowlingUI.prototype, "gameProgress", undefined);
def_BowlingUI = _n7 = cc__decorate([ccp_ccclass], def_BowlingUI);
exports.default = def_BowlingUI;